package view;

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JPanel;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JApplet;
import javax.swing.SwingUtilities;

public class MarkPen extends JApplet {
	public MarkPen() {
	}
static int cont=1;

   public static class DrawPanel extends JPanel {

       private List<Point> points = new ArrayList<Point>();

       public DrawPanel() {
           setBackground(Color.WHITE);

           addMouseMotionListener(new MouseAdapter() {

               @Override
               public void mouseDragged(MouseEvent e) {
            	  
            	   
                   points.add(e.getPoint());
                   repaint();
               }
           });

           addMouseListener(new MouseAdapter(){

               @Override
               public void mousePressed(MouseEvent e){
            	  
            	   if((cont%2)==0)
            	   {
            		   points.clear();
                       repaint();
                       cont++;
                       //System.out.println(""+cont);
            	   }
            	   else
            	   {
                   Point p = null;
                   points.add(p);
                   cont++;
            	   }
                   
            }
           });
           
       }

       protected void paintComponent(java.awt.Graphics g) {
           super.paintComponent(g);
           Point p1 = null;
           Point p2 = null;
           g.setColor(Color.black);

           ((Graphics2D) g).setStroke(new BasicStroke(3));
           for (Point p : points) {
               p2 = p1;
               p1 = p;
               if (p1 != null && p2 != null) {
                   g.drawLine(p1.x, p1.y, p2.x, p2.y);
                  
               }
           }
       }
       
   }

  
}